<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title>修理</title>
		<!--标准mui.css-->
		<link rel="stylesheet" href="../css/mui.min.css">
		<script src="../js/jquery.min.js"></script>
		<script src="../js/mui.min.js"></script>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">维修列表</h1>
		</header>
		<div class="mui-content">
			<ul class="mui-table-view" id="con">
				<!-- --------------------------数据填充----------------------------------------- -->
				<li class="mui-table-view-cell mui-media" name="123">
					<img class="mui-media-object mui-pull-left" src="../image/u=675629265,2686821793&fm=26&gp=0.jpg">
					<div class="mui-media-body">
						教室
						<p class='mui-ellipsis'>空调坏了</p>
					</div>
				</li>
				<li class="mui-table-view-cell mui-media" name="123">
					<img class="mui-media-object mui-pull-left" src="../image/u=675629265,2686821793&fm=26&gp=0.jpg">
					<div class="mui-media-body">
						教室
						<p class='mui-ellipsis'>空调坏了</p>
					</div>
				</li>
				<!-- --------------------------数据填充----------------------------------------- -->
			</ul>
		</div>
	</body>

	<script>
		//mui初始化
		mui.init({
			swipeBack: true, //启用右滑关闭功能
			gestureConfig: {
				tap: true, //默认为true
				doubletap: true, //默认为false
				longtap: true, //默认为false
				swipe: true, //默认为true
				drag: true, //默认为true
				hold: false, //默认为false，不监听
				release: false //默认为false，不监听
			}
		});

		var user_id;
		mui.plusReady(function() {
			user_id = plus.storage.getItem("user_id");
			init();
		}); 

		mui(".mui-content").on('longtap', 'li', function() {
			var name = this.getAttribute("name");
			var btnArray = ['否', '是'];
			mui.confirm('已完成？', '警告', btnArray, function(e) {
				if (e.index == 1) {
					solve(name);
				} else {
					mui.toast('您已取消该操作');
				}
			})
		});
		
		function init(){
			mui.ajax({
				url: '', 
				type: "post",
				async: false,
				data: {},
				dataType: "json",
				contentType: "application/x-www-form-urlencoded; charset=utf-8",
				jsonp: "jsoncallback",
				success: function(data) {
					var Ele = jQuery("#con");
					Ele.empty();
					var Info = data.gear_list;
					for (var i = 0, l = Info.length; i < l; i++) {
						var tempEle = ' <li class="mui-table-view-cell mui-media" name='+ Info[i]['id'] + '>' +
							'<img class="mui-media-object mui-pull-left" src="'+ Info[i]['pic']  +'">'+
							'<div class="mui-media-body">'+Info[i]['kind'] +
							'<p class="mui-ellipsis">'+ Info[i]['description']+ '</p>'+
							'</div></li>';
							Ele.append(tempEle)
					}
				},
				error: function() {
					mui.toast("网络开小差了");
				}
			});
			mui.toast('长按即可代表已经维修好');
		}
		
	
		function solve(name) {
			mui.ajax({
				url: '', 
				type: "post",
				data: {
					"user_id": user_id,
					'name': name
				},
				dataType: "json",
				contentType: "application/x-www-form-urlencoded; charset=utf-8",
				jsonp: "jsoncallback",
				success: function(data) {
					if (data['suc']) {
						mui.toast("操作成功");
					} else {
						mui.toast("操作失败");
					}
				},
				error: function() {
					mui.toast("网络开小差了");
				}
			});
		}
		
	</script>
</html>
